2022. 10. 26
시스템운영팀
파이썬 기초 교육
1. Life is short, You need Python.
귀도 로섬(Guido van Rossum, 1956. 1. 31 ~)
파이썬은 1989 크리스마스 주에, 연구실이 닫혀 있어서
심심한 김에 만든 프로그래밍 언어이다.
198912, 저는 크리스마스 주중에 저의 "취미" 될만한
프로그램을 찾고 있었습니다.“
1999, 로섬은 DARPA에게 Computer Programming for Everybody라는
자금 제안서를 제출하여 Python 대한 자신의 목표를 정의했습니다.
당연히 무료이며 오픈 소스이므로 누구나 개발할 있습니다.
평이한 영어로 이해할 있는 코드, 일상적인 업무에 대한 적합성과
짧은 개발 시간등 장점을 기반으로 파이썬은 대중적인
프로그래밍 언어가 되었습니다.
참고로, 파이썬이라는 이름은 귀도가 즐겨 보던 영국의 6인조 코미디 그룹
몬티 파이썬에서 따왔다고 한다.
https://ko.wikipedia.org/wiki/귀도__로섬
2. 202210 현재 “인기있는 프로그래밍 언어들”
TIOBE Index 2022.10.21
3. 파이썬의 철학
"아름다운 추한 것보다 낫다." (Beautiful is better than ugly)
"명시적인 것이 암시적인 보다 낫다." (Explicit is better than implicit)
"단순함이 복잡함보다 낫다." (Simple is better than complex)
"복잡함이 난해한 것보다 낫다." (Complex is better than complicated)
"가독성은 중요하다." (Readability counts)
The Zen of Python
4. 이해하기 쉬워요
Assembly Python Scratch
C
5. 파이썬의 특징
“문법이 쉽고 순서가 영어 구문과 유사하여 빠르게 배울 있다.“
- Easy-to-learn: 적은 키워드, 구조가 간단, 명확한 구문
- Easy-to-read: 간결한 코드, 높은 가독성
- Easy-to-maintain: 유지관리가 쉽다
“풍부한 라이브러리로 개발 생산성이 매우 높다.“
- Numpy, Pandas, Matplotlib, lpython, Django, Flask
“다양한 플랫폼에서 사용 가능“
- Windows, Mac, Unix, Linux에서 동일하게 구동
6. 무엇을 있을까?
Part 1
환경설정
1. 환경설정
파이썬
Python
1.1 파이썬 설치
1) 구글에 python검색
2) 파이 공식 홈페이지 방문
3) 설치 파일 다운로드
4) 설치 파일 실행
5) Add Python 3.x to PATH 체크
6) Customize installation 선택
7) Next 클릭
8) C:\Python3x 변경
9) Install 클릭
10)Close 클릭
https://www.python.org/ftp/python/3.10.8/pyt
hon-3.10.8-amd64.exe
1.2 비주얼 스튜디오 코드 설치
1) 구글에서 vscode검색
2) 공식 홈페이지 방문
3) 설치 파일 다운로드
4) 설치 파일 실행
5) 계약에 동의함 선택
6) 다음 계속 클릭
7) 설치 클릭
8) 마침 클릭
9) 바탕화면 OneMinPython 폴더 생성
10) Open Folder 클릭
11) OoneMinPython 폴더 선택
12) New File > hello_world.py 파일 생성
13) Python extension Install 클릭
14) print(hello world) 입력
15) 저장 실행
16) 결과 확인
https://code.visualstudio.com/Download#
1.3 hello world
실행법2 : python hello_world.py
실행법1
학습파일: 01_hello_world.py
https://github.com/DaeyoungHan/power_user_edu
Part 2
별찍기
2. 출력해보기
학습파일: 02_star.py
Part 3
Ctrl C, Ctrl V
이해하려 하지 말기
3. 랜덤하면서 중복되지 않은 숫자 뽑기
import random
lotto = random.sample(range(1, 45), 6)
print("로또번호: {}".format(lotto))
import random
lotto = []
rnd_num = random.randint(1, 45)
for i in range(6):
while rnd_num in lotto:
rnd_num = random.randint(1, 45)
lotto.append(rnd_num)
lotto.sort()
print("로또번호: {}".format(lotto))
학습파일: 03_random_number_1.py
03_random_number_2.py
3. 네이버에서 환율 가져오기
# pip install beautifulsoup4
# pip install requests
import requests
from bs4 import BeautifulSoup
header = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
url = "https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=%EB%8B%AC%EB%9F%AC%EC%9B%90%ED%99%94%ED%99%98%EC%9C%A8"
response = requests.get(url=url, headers=header)
if response.status_code == 200:
html = response.text
soup = BeautifulSoup(html, 'html.parser')
currency_tag = soup.select_one('#_cs_foreigninfo > div > div.api_cs_wrap > div > div.c_rate
div.input_box._input_box > span.recite._recite.result')
print(currency_tag)
print(currency_tag.getText())
else:
print(response.status_code)
학습파일: 03_web_scraping_ex_1.py
3. exe 파일 만들기
# pip install pyinstaller
import random
import os
lotto = random.sample(range(1, 45), 6)
print("로또번호: {}".format(lotto))
os.system('pause')
# pyinstaller --clean --onefile 03_exe_file_create.py
학습파일: 03_exe_file_create.py
Part 4
기본 개념
4.1 자료형
신규 회원 가입
이름
주소
나이
홍길동
광주광역시 광산구 손재
20
마케팅 정보 제공에 동의합니다.
문자 자료형
숫자 자료형
불리언 자료형
4.1 자료형
4.2 변수
4.2 변수 선언, 변수 사용
4.2 변수 이름 규칙
4.3 연산자
4.3 연산자
4.4 주석
4.4 주석
4.5 모듈, 패키지, 라이브러리
1) 모듈
특정 기능을 .py 파일 단위로 작성한
2) 패키지
특정 기능과 관련된 여러 모듈을 묶은
3) 라이브러리
모듈과 패키지, 내장 함수를 묶어서
라이브러리라 부름
4.5 모듈 사용해보기
모듈의 사용(import)
import 모듈
import 모듈1, 모듈2, 모듈3 …
import 모듈 as 별명
from 모듈 import 함수
from 모듈 import 함수1, 함수2, 함수3
모듈의 사용(import)
import datetime
import math, random
import math as m
from math import pi
from math import *
4.5 모듈 사용 예시
import datetime
import math
import math as m
from math import pi
from math import *
now = datetime.datime.now() # import datetime
print(now)
print(“The value of pi is”, math.pi) # import math
print(“The value of pi is”, m.pi) # import math as m
print(“The value of pi is”, pi) # from math import pi
print(“The value of e is”, e) # from math import *
Part 5
학습 참고자료
참고자료
[나도 코딩]
블로그: https://nadocoding.tistory.com
- 1 파이썬 통합본
https://nadocoding.tistory.com/m/93
유튜브: https://www.youtube.com/channel/UC7iAOLiALt2rtMVAWWl4pnw
- 1파이썬
https://www.youtube.com/playlist?list=PLMsa_0kAjjrcxiSJnHNfzBN71D3zpYtkX
※ 본 교육자료는 “나도코딩 - 1 파이썬강좌를 기초로 작성되었으며, 자료 사용에 원작자의 사전동의를 구했음을 안내 드립니다.
[유용한 강좌 모음]
1. 파이썬 공식 자습서: https://docs.python.org/ko/3/tutorial/index.html
2. 위키독스: https://wikidocs.net/
3. 생활코딩: https://opentutorials.org/course/4769
[심화 과정]
1. 웹스크래핑
-셀레니움 사용법: https://lrl.kr/dVK6
-뷰티풀수프 사용법: https://lrl.kr/bPGB
2. 딥러닝
-https://wikidocs.net/32829
[교육 자료]
https://github.com/DaeyoungHan/power_user_edu
Q&A